<template>
  <div class="classroom">
    <!-- 个人中心页 -->
    <header>
      <h2>开启吃货之旅</h2>
      <div>
        <!-- <h3 v-if="token">{{ userName | setUserName }}</h3> -->
        <div class="user-title" v-if="token">
          <img :src="picUrl" :alt="picUrl">
          <!-- <img src="../assets/img/user-title.jpg" alt=""> -->
        </div>
        <router-link v-else to="/login"><van-icon size="50"
            name="https://b.yzcdn.cn/vant/icon-demo-1126.png" /></router-link>
      </div>
    </header>

    <section>
      <div class="list">
        <ul>
          <li @click="myFav">
            <div><span>我的收藏</span></div>
            <div><van-icon name="star-o" /></div>
          </li>
          <li @click="myCRoom">
            <div><span>我的课程</span></div>
            <van-icon name="video-o" />
          </li>
          <li @click="opinions">
            <div><span>意见反馈</span></div>
            <van-icon name="records-o" />
          </li>
          <li @click="share">
            <div><span>把菜谱大全分享给朋友</span></div>
            <van-icon name="share-o" />
          </li>
          <li @click="logOut">
            <div><span>设置</span></div>
            <van-icon name="setting-o" />
          </li>
        </ul>
      </div>
      <p>V7.14.2</p>
    </section>
  </div>
</template>

<script>
import { Dialog } from 'vant';

// 初始化（获取存储在本地的所有用户信息）
let sky_users = []
let sky_users_str = localStorage.getItem("SKY_USERS")
if (sky_users_str) {
  // 如果本地有存储用户信息，就把这个存储信息的字符串转成数组
  sky_users = JSON.parse(sky_users_str)
}

export default {
  data() {
    return {
      token: false,
      userName: "",
      picUrl: require("../assets/img/user-title.jpg")
    }
  },
  methods: {
    // 我的收藏
    myFav() {
      Dialog.alert({
        message: '敬请期待！',
      }).then(() => {
        // on close
      });
    },
    // 我的课程
    myCRoom() {
      Dialog.alert({
        message: '敬请期待！',
      }).then(() => {
        // on close
      });
    },
    // 意见反馈
    opinions() {
      Dialog.alert({
        message: '敬请期待！',
      }).then(() => {
        // on close
      });
    },
    // 把菜谱大全分享给朋友
    share() {
      Dialog.alert({
        message: '敬请期待！',
      }).then(() => {
        // on close
      });
    },
    // 设置
    logOut() {
      this.$router.push({ path: '/logout' })
    }

  },
  // 过滤器
  // filters: {
  //   setUserName(value) {
  //     // console.log(value);
  //     return value.slice(0, 4) + "...";
  //   }
  // },
  // 初始化钩子函数
  created() {
    // 赋值
    let token = localStorage.getItem("AUTO_TOKEN");
    this.token = token;
    // let arr = sky_users.filter(item => item.id == token);
    // if (arr) {
    //   // 获取用户名
    //   // this.userName = arr[0].username;
    //   // console.log(arr);
    // }
  },

}
</script>

<style lang="less" scoped>
@import url(../common/less/varible.less);

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: @pad;
  padding-top: 80px;

  h2 {
    font-size: 23px;
  }

  .user-title>img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
  }
}

section {
  .list {
    width: 100%;
    padding: @pad;
    padding-top: 30px;

    ul {
      width: 100%;

      li {
        display: flex;
        justify-content: space-between;
        font-size: 15px;
        padding: 15px 0;
        border-bottom: 1px solid @borderColor;
      }
    }
  }

  p {
    color: #666;
    text-align: center;
    padding-top: 100px;
    font-size: 12px;
  }

}
</style>